-
Notifications
You must be signed in to change notification settings - Fork 30.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prototyping new CodeAction API #36316
Conversation
93ee798
to
305d6a6
Compare
@jrieken Kai and I were talking today and wanted to try out a different API design than in #34664. The current change introduces two separate interfaces The implementation still need lots of work but please take a look at |
I like the general direction but not the change 🙊. I think the class QuickFix {
command: Command
addresses: Diagnostics[]
} alternatively, in case we make add support for text edits, add a title class QuickFix {
title: string;
fix: Command | WorkspaceEdit | TextEdit
addresses: Diagnostics
} or making it even more compact, with only one type class CodeAction {
// ... all from above
// when set treated as quick fix, otherwise as refactoring
addresses?: Diagnostic[]
} |
Some inspiration from roslyn: http://source.roslyn.io/#Microsoft.CodeAnalysis.Workspaces/CodeFixes/CodeFix.cs,7161867d561915e6 There seems to be a |
/cc @DustinCampbell for some background how roslyn handles refactorings vs fixes. |
In Roslyn...
Does that help? |
Thanks @DustinCampbell! Very helpful design to review. Do you happen to know how VS sets up keybindings for specific refactoring, such as |
@jrieken Today @kieferrm and I talked through the design again and cut it back to focus on address three problems:
The first two are addressed by adding a new For the third, one thought is to keep refactoring as code actions for now, but give code action providers additional context so that they can decide which actions to return. This latest change enables this by adding a |
There's no general API for this. It's done on a case-by-case basis. 😞 |
b710b7d
to
3f5b738
Compare
@@ -39,13 +46,15 @@ export class QuickFixController implements IEditorContribution { | |||
constructor(editor: ICodeEditor, | |||
@IMarkerService markerService: IMarkerService, | |||
@IContextKeyService contextKeyService: IContextKeyService, | |||
@ICommandService commandService: ICommandService, | |||
@ICommandService private readonly commandService: ICommandService, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_
for privates please
src/vs/editor/common/modes.ts
Outdated
@@ -284,7 +292,7 @@ export interface CodeActionProvider { | |||
/** | |||
* Provide commands for the given document and range. | |||
*/ | |||
provideCodeActions(model: editorCommon.IReadOnlyModel, range: Range, token: CancellationToken): Command[] | Thenable<Command[]>; | |||
provideCodeActions(model: editorCommon.IReadOnlyModel, range: Range, token: CancellationToken): (Command | CodeAction)[] | Thenable<(Command | CodeAction)[]>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this land we can break the API so I'd suggest we don't carry along the Command | CodeAction
notion but just make it a CodeAction
. I'd also do that on the protocol layer and do the Command
becomes CodeAction
thing in the code action adapter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm concerned this will break the vscode.executeCodeActionProvider
command. I believe this should still return commands instead of code actions for old providers and so I'm going to revert the change to only use code actions for now
|
||
const allResults: Command[] = []; | ||
const allResults: (Command | CodeAction)[] = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CodeAction
ftw
if ('id' in action) { | ||
// must be a command | ||
const command = action as Command; | ||
return { title: command.title, command: command } as CodeAction; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CodeAction
ftw, lets do the conversion in the ext host
constructor( | ||
private readonly editor: ICodeEditor, | ||
private readonly contextMenuService: IContextMenuService, | ||
private readonly onApplyCodeAction: (action: CodeAction) => TPromise<any> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary change, _
for privates
return { | ||
title: codeAction.title, | ||
command: codeAction.command ? this._commands.toInternal(codeAction.command) : undefined, | ||
edits: codeAction.edits |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the sake of simplicity we can also make edits
always a WorkspaceEdit
. We'd treat the TextEdit
as sugar and translate it into a workspace edit... Makes the internal CodeAction simpler and easier to handle.
I would have gone ahead but there are some merge-conflicts... |
Adds skeleton on a new CodeActionType and allows codeActionProvider to return either `Command`s or `CodeAction`s Move proposed CodeAction API to proposed and try using it in TS Split CodeAction into quickfix and refactoring classes Update proposed interface Update for new API Adding basic docs
…nd` in modes since this will break `vscode.executeCodeActionProvider`
Adds skeleton of a new
CodeAction
type and allows codeActionProviders to return eitherCommand
s orCodeAction
s